<template>
	<view class="safe-check-list">
		<view class="add-button">
			<van-button type="primary" size="small" @click="toAdd">
				新增
			</van-button>
		</view>
		<view class="safe-check-container">
			<van-empty v-if="notifyList.length < 1" description="没有更多了" />
			<view class="safe-check-item" v-for="(item, index) in notifyList" :key="index">
				<view class="safe-check-item-left">
					<view>
						检查日期：{{ item.createTime.substring(0,10).replaceAll('-','/') }}
					</view>
					<view style="margin-top: 16rpx;">
						工程地点：{{ item.address }}
					</view>
				</view>
				<view class="safe-check-item-right">
					<van-button size="small" @click="toDetail(item)">
						查看
					</van-button>
				</view>
			</view>
			<view></view>
		</view>
	</view>
</template>

<script>
	import {
		getCheckList
	} from '@/request/api.js'
	export default {
		data() {
			return {
				userId: '',
				notifyList: []
			};
		},
		onLoad() {
			uni.$on('refreshCheck', () => {
				this.init()
			})
			uni.getStorage({
				key: 'userInfo',
				success: (res) => {
					this.userId = res.data[0].account
					this.init()
				}
			})
		},
		onBackPress() {
			this.init()
		},
		methods: {
			toAdd() {
				uni.navigateTo({
					url: '../safe_check/safe_check?pageType=0'
				})
			},
			toDetail(item) {
				uni.navigateTo({
					url: `../safe_check/safe_check?pageType=1&detailId=${item.id}`
				})
			},
			init() {
				getCheckList({
					UserID: this.userId
				}).then(res => {
					this.notifyList = res.result
					// this.notifyList = []
					// res.result.forEach((element, index) => {
					// 	var aData = new Date(Date.parse(element.createTime))
					// 	var month = aData.getMonth() < 9 ? "0" + (aData.getMonth() + 1) : aData.getMonth() + 1;
					// 	var date = aData.getDate() <= 9 ? "0" + aData.getDate() : aData.getDate();
					// 	element.createTime = aData.getFullYear() + "/" + month + "/" + date;
					// 	this.notifyList.push(element)
					// })
				})
			}
		}
	}
</script>

<style lang="scss">
	.safe-check-list {
		padding: 32rpx;
		height: 100vh;
		width: 100vw;
		box-sizing: border-box;
		background-color: #F8F8F8;

		.add-button {
			display: block;
			text-align: right;
		}

		.safe-check-container {

			// .safe-check-item:first-child{
			//   margin-top: 0;
			// }
			.safe-check-item {
				display: flex;
				align-items: center;
				margin-top: 32rpx;
				background-color: #FFFFFF;
				padding: 32rpx;
				box-sizing: border-box;
				border-radius: 24rpx;

				.safe-check-item-left {
					flex: 1;
					font-size: 32rpx;
				}

				.safe-check-item-right {}
			}
		}
	}
</style>
